package com.gzhryc.shared_device.oem.h5.agent.controllers.api.v1.bxscn;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.gzhryc.common.NumberTools;
import com.gzhryc.common.StringTools;
import com.gzhryc.common.api.DefaultAPIResponse;
import com.gzhryc.common.exceptions.LogicException;
import com.gzhryc.servlet.WebUtils;
import com.gzhryc.servlet.annotation.Route;
import com.gzhryc.shared_device.bxscn.code.dao.db.BXSCNBatteryTypeDayCost;
import com.gzhryc.shared_device.bxscn.code.dao.db.BXSCNShopFeeTemplate;
import com.gzhryc.shared_device.bxscn.code.dao.db.BXSCNShopFeeTemplateItem;
import com.gzhryc.shared_device.bxscn.code.dao.enums.BXSCNShopFeeTemplateItemEnum;
import com.gzhryc.shared_device.bxscn.code.dao.models.BXSCNShopFeeTemplateItemCount;
import com.gzhryc.shared_device.bxscn.code.services.BXSCNBatteryTypeDayCostService;
import com.gzhryc.shared_device.bxscn.code.services.BXSCNShopFeeTemplateService;
import com.gzhryc.shared_device.oem.code.agent.dao.db.AgentRelationBusinessConfig;
import com.gzhryc.shared_device.oem.code.agent.dao.enums.AgentRelationBusinessConfigEnum;
import com.gzhryc.shared_device.oem.code.agent.services.AgentRelationBusinessConfigService;
import com.gzhryc.shared_device.oem.code.business.EBusinessType;
import com.gzhryc.shared_device.oem.code.place.services.PlaceBusinessConfigService;
import com.gzhryc.shared_device.oem.code.user.ERoleType;
import com.gzhryc.shared_device.oem.h5.agent.ClientAPICodeConstants;
import com.gzhryc.shared_device.oem.h5.agent.LoginUser;
import com.gzhryc.shared_device.oem.h5.agent.WebConstants;
import com.gzhryc.shared_device.oem.h5.agent.dto.api.v1.bxscn.BXSCNFeeTemplateDelRequest;
import com.gzhryc.shared_device.oem.h5.agent.dto.api.v1.bxscn.BXSCNShopFeeTemplateInfoRequest;
import com.gzhryc.shared_device.oem.h5.agent.dto.api.v1.bxscn.BXSCNShopFeeTemplateInfoResponse;
import com.gzhryc.shared_device.oem.h5.agent.dto.api.v1.bxscn.BXSCNShopFeeTemplateItemDelRequest;
import com.gzhryc.shared_device.oem.h5.agent.dto.api.v1.bxscn.BXSCNShopFeeTemplateItemSaveRequest;
import com.gzhryc.shared_device.oem.h5.agent.dto.api.v1.bxscn.BXSCNShopFeeTemplateListResponse;
import com.gzhryc.shared_device.oem.h5.agent.dto.api.v1.bxscn.BXSCNShopFeeTemplateSaveRequest;

public class BXSCNShopFeeTemplateController {

	@Route(value = "/agent/api/v1/bxscn/shop/fee_template/list.data")
    public BXSCNShopFeeTemplateListResponse list(HttpServletRequest request) {
		BXSCNShopFeeTemplateListResponse apiResp = new BXSCNShopFeeTemplateListResponse(ClientAPICodeConstants.NULL_DATA, "暂无数据");
        LoginUser loginUser = WebUtils.getAttribute(request, WebConstants.ATTR_LOGIN_USER, LoginUser.class);
        if (loginUser != null) {
            List<BXSCNShopFeeTemplate> feeTemplateList = null;
            if(ERoleType.Agent.index().equals(loginUser.getRoleType())){
                feeTemplateList = BXSCNShopFeeTemplateService.self().findByUserId(loginUser.getId());
            }else if(ERoleType.Partner.index().equals(loginUser.getRoleType())){
                feeTemplateList = BXSCNShopFeeTemplateService.self().findByUserId(loginUser.getParentId());
            }
            
            if(feeTemplateList != null && feeTemplateList.size() > 0) {
                 List<Long> templateIds = new ArrayList<>();
                 for(BXSCNShopFeeTemplate feeTemplate : feeTemplateList) {
                	 templateIds.add(feeTemplate.getId());
                 }
                  
                 List<BXSCNShopFeeTemplateItemCount> feeTemplateItemCountList = BXSCNShopFeeTemplateService.self().findByTemplateIds(templateIds);
             
                 for(BXSCNShopFeeTemplate feeTemplate : feeTemplateList) {
                	 feeTemplate.setItemCount(0L);
                	 if(feeTemplateItemCountList != null && feeTemplateItemCountList.size() > 0) {
                		 for(BXSCNShopFeeTemplateItemCount feeTemplateItemCount : feeTemplateItemCountList) {
                			 if(feeTemplateItemCount.getTemplateId().equals(feeTemplate.getId())) {
                				 feeTemplate.setItemCount(feeTemplateItemCount.getItemCount());
                				 break;
                			 }
                		 }
                	 }
                 }
            }
            
            apiResp.setCode(ClientAPICodeConstants.SUCCESS,null);
            apiResp.getBody().setItems(new ArrayList<>());
            
            BXSCNShopFeeTemplateListResponse.Item item = new BXSCNShopFeeTemplateListResponse.Item();
   		 	item.setId(0L);
   		 	item.setTitle("全局模版");
   		 	
   		 	Long total = BXSCNBatteryTypeDayCostService.self().count();
   		 	item.setItemCount(total.intValue());
   		 	
   		 	apiResp.getBody().getItems().add(item);
            
            if(feeTemplateList != null && feeTemplateList.size() > 0) {
            	 for(BXSCNShopFeeTemplate feeTemplate : feeTemplateList) {
            		 item = new BXSCNShopFeeTemplateListResponse.Item();
            		 item.setId(feeTemplate.getId());
            		 item.setTitle(feeTemplate.getTitle());
            		 item.setItemCount(feeTemplate.getItemCount().intValue());
            		 item.setCreateDate(feeTemplate.getCreateDate());
            		 apiResp.getBody().getItems().add(item);
            	 }
            }
        }
        return apiResp;
    }
	
	@Route(value = "/agent/api/v1/bxscn/shop/fee_template/info.data")
    public BXSCNShopFeeTemplateInfoResponse info(HttpServletRequest request) {
		BXSCNShopFeeTemplateInfoResponse apiResp = new BXSCNShopFeeTemplateInfoResponse(ClientAPICodeConstants.NULL_DATA, "暂无数据");
		BXSCNShopFeeTemplateInfoRequest apiReq = WebUtils.getJsonRequest(request, BXSCNShopFeeTemplateInfoRequest.class);
        LoginUser loginUser = WebUtils.getAttribute(request, WebConstants.ATTR_LOGIN_USER, LoginUser.class);
        if (loginUser != null && apiReq != null && apiReq.getBody().getTemplateId() != null) {
        	BXSCNShopFeeTemplate feeTemplate = BXSCNShopFeeTemplateService.self().getById(apiReq.getBody().getTemplateId());
        	if(feeTemplate != null) {
	            if(ERoleType.Agent.index().equals(loginUser.getRoleType())){
	            	if(!feeTemplate.getUserId().equals(loginUser.getId())) {
	            		apiResp.setCode(ClientAPICodeConstants.NOT_POWER, "无权限查看");
	            		return apiResp;
	            	}
	            }else if(ERoleType.Partner.index().equals(loginUser.getRoleType())){
	            	if(!feeTemplate.getUserId().equals(loginUser.getParentId())) {
	            		apiResp.setCode(ClientAPICodeConstants.NOT_POWER, "无权限查看");
	            		return apiResp;
	            	}
	            }else {
	            	apiResp.setCode(ClientAPICodeConstants.NOT_POWER, "无权限查看");
            		return apiResp;
	            }
        	}
            
        	String resDomain = WebConstants.getResDomain(request);
            List<BXSCNBatteryTypeDayCost> batteryTypeDayCostList = BXSCNBatteryTypeDayCostService.self().findJoinAll(); 
            
            if(feeTemplate != null) {
	            List<BXSCNShopFeeTemplateItem> feeTemplateItemList = BXSCNShopFeeTemplateService.self().findItemByTemplateId(apiReq.getBody().getTemplateId());
	            
	            apiResp.setCode(ClientAPICodeConstants.SUCCESS, null);
	            apiResp.getBody().setId(feeTemplate.getId());
	            apiResp.getBody().setTitle(feeTemplate.getTitle());
	            
	            if(batteryTypeDayCostList != null && batteryTypeDayCostList.size() > 0) {
	            	apiResp.getBody().setItems(new ArrayList<>());
	            	for(BXSCNBatteryTypeDayCost batteryTypeDayCost : batteryTypeDayCostList) {
		            	BXSCNShopFeeTemplateInfoResponse.Item item = new BXSCNShopFeeTemplateInfoResponse.Item();
		        		item.setBatteryTypeId(batteryTypeDayCost.getTypeId());
		        		item.setBatteryTypeName(batteryTypeDayCost.getBatteryType().getName());
		        		if(StringTools.isNotBlank(batteryTypeDayCost.getBatteryType().getThumbnailImg())) {
		        			item.setBatteryTypeImg(WebUtils.setHttpDomain(resDomain, batteryTypeDayCost.getBatteryType().getThumbnailImg()));
		        		}
		        		item.setCostItems(new ArrayList<>());
		        		
		        		BXSCNShopFeeTemplateInfoResponse.CostItem costItem = new BXSCNShopFeeTemplateInfoResponse.CostItem();
		        		
		        		costItem.setType(BXSCNShopFeeTemplateItemEnum.Type.Normal.index());
		        		costItem.setTypeName(BXSCNShopFeeTemplateItemEnum.Type.Normal.note());
		        		costItem.setDepositPrice(batteryTypeDayCost.getDepositMoneyStr());
		        		costItem.setDayPrice(batteryTypeDayCost.getDayMoneyStr());
		        		costItem.setState(1);
		        		item.getCostItems().add(costItem);
		        		
		        		boolean canDelete = false;
		        		if(feeTemplateItemList != null && feeTemplateItemList.size() > 0) {
		                	for(BXSCNShopFeeTemplateItem feeTemplateItem : feeTemplateItemList) {
		                		if(feeTemplateItem.getBatteryTypeId().equals(batteryTypeDayCost.getTypeId())) {
		                			if(BXSCNShopFeeTemplateItemEnum.Type.Normal.index().equals(feeTemplateItem.getType())) {
		                				costItem.setDepositPrice(feeTemplateItem.getDepositMoneyStr());
		                				costItem.setDayPrice(feeTemplateItem.getDayMoneyStr());
		                				costItem.setState(2);
		                				canDelete = true;
		                			}else {
		                				BXSCNShopFeeTemplateInfoResponse.CostItem costItem2 = new BXSCNShopFeeTemplateInfoResponse.CostItem();
		                				costItem2.setType(feeTemplateItem.getType());
		                				costItem2.setTypeName(feeTemplateItem.getTypeName());
		                				costItem2.setDepositPrice(feeTemplateItem.getDepositMoneyStr());
		                				costItem2.setDayPrice(feeTemplateItem.getDayMoneyStr());
		                				costItem2.setState(2);
		            	        		item.getCostItems().add(costItem2);
		            	        		canDelete = true;
		                			}
		                		}
		                	}
		                }
		        		item.setCanDelete(canDelete);
		        		apiResp.getBody().getItems().add(item);
	            	}
	            }
            }else if(apiReq.getBody().getTemplateId() == 0){
            	apiResp.setCode(ClientAPICodeConstants.SUCCESS, null);
	            apiResp.getBody().setId(0L);
	            apiResp.getBody().setTitle("全局模版");
	            apiResp.getBody().setItems(new ArrayList<>());
	            
	            for(BXSCNBatteryTypeDayCost batteryTypeDayCost : batteryTypeDayCostList) {
	            	BXSCNShopFeeTemplateInfoResponse.Item item = new BXSCNShopFeeTemplateInfoResponse.Item();
	        		item.setBatteryTypeId(batteryTypeDayCost.getTypeId());
	        		item.setBatteryTypeName(batteryTypeDayCost.getBatteryType().getName());
	        		if(StringTools.isNotBlank(batteryTypeDayCost.getBatteryType().getThumbnailImg())) {
	        			item.setBatteryTypeImg(WebUtils.setHttpDomain(resDomain, batteryTypeDayCost.getBatteryType().getThumbnailImg()));
	        		}
	        		item.setCostItems(new ArrayList<>());
	        		
	        		BXSCNShopFeeTemplateInfoResponse.CostItem costItem = new BXSCNShopFeeTemplateInfoResponse.CostItem();
	        		
	        		costItem.setType(BXSCNShopFeeTemplateItemEnum.Type.Normal.index());
	        		costItem.setTypeName(BXSCNShopFeeTemplateItemEnum.Type.Normal.note());
	        		costItem.setDepositPrice(batteryTypeDayCost.getDepositMoneyStr());
	        		costItem.setDayPrice(batteryTypeDayCost.getDayMoneyStr());
	        		costItem.setState(1);
	        		item.getCostItems().add(costItem);
	        		
	        		apiResp.getBody().getItems().add(item);
	            }
            }else {
            	apiResp.setCode(ClientAPICodeConstants.NOT_POWER, "无权限查看");
            	return apiResp;
            }
        }
        return apiResp;
    }

	@Route(value = "/agent/api/v1/bxscn/shop/fee_template/save.do")
    public DefaultAPIResponse save(HttpServletRequest request) {
        DefaultAPIResponse apiResp = new DefaultAPIResponse(ClientAPICodeConstants.EXECUTE_ERROR, "保存收费模版失败");
        BXSCNShopFeeTemplateSaveRequest apiReq = WebUtils.getJsonRequest(request, BXSCNShopFeeTemplateSaveRequest.class);
        if (apiReq != null) {
            LoginUser loginUser = WebUtils.getAttribute(request, WebConstants.ATTR_LOGIN_USER, LoginUser.class);
            if (loginUser != null) {
                Long userId = loginUser.getId();
                if(!ERoleType.Agent.index().equals(loginUser.getRoleType())){
                    if(ERoleType.Partner.index().equals(loginUser.getRoleType())) {
                        userId = loginUser.getParentId();
                        AgentRelationBusinessConfig agentRelationBusiConfig = AgentRelationBusinessConfigService.self()
                        		.getByKeys(loginUser.getParentId(), loginUser.getId(),EBusinessType.BXSCN_SHOP.index());
                        if(agentRelationBusiConfig == null || AgentRelationBusinessConfigEnum.EditFeeState.Close.index()
                        		.equals(agentRelationBusiConfig.getEditFeeState())) {
                        	 apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限保存收费模版");
                             return apiResp;
                        }
                    }else{
                        apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限保存收费模版");
                        return apiResp;
                    }
                }

                if(StringTools.isBlank(apiReq.getBody().getTitle())){
                    apiResp.setMsg("请填写模版标题");
                    return apiResp;
                }
                
                BXSCNShopFeeTemplate feeTemplate = new BXSCNShopFeeTemplate();
                feeTemplate.setId(apiReq.getBody().getId());
                feeTemplate.setUserId(userId);
                feeTemplate.setTitle(apiReq.getBody().getTitle());

                if(feeTemplate.getId() != null) {
                    try {
                        if(BXSCNShopFeeTemplateService.self().updateNotNull(feeTemplate)){
                            apiResp.setCode(ClientAPICodeConstants.SUCCESS,null);
                        }
                    } catch (LogicException e) {
                        apiResp.setMsg(e.getMessage());
                    }
                }else{
                    try {
                        if(BXSCNShopFeeTemplateService.self().add(feeTemplate)){
                            apiResp.setCode(ClientAPICodeConstants.SUCCESS,null);
                        }
                    } catch (LogicException e) {
                        apiResp.setMsg(e.getMessage());
                    }
                }
            }
        }
        return apiResp;
    }
	
	@Route(value = "/agent/api/v1/bxscn/shop/fee_template/item/save.do")
    public DefaultAPIResponse saveItem(HttpServletRequest request) {
        DefaultAPIResponse apiResp = new DefaultAPIResponse(ClientAPICodeConstants.EXECUTE_ERROR, "保存电池类型价格失败");
        BXSCNShopFeeTemplateItemSaveRequest apiReq = WebUtils.getJsonRequest(request, BXSCNShopFeeTemplateItemSaveRequest.class);
        if (apiReq != null && apiReq.getBody().getTemplateId() != null && StringTools.isNotBlank(apiReq.getBody().getBatteryTypeId())
        		&& apiReq.getBody().getItems() != null && apiReq.getBody().getItems().size() > 0) {
            LoginUser loginUser = WebUtils.getAttribute(request, WebConstants.ATTR_LOGIN_USER, LoginUser.class);
            if (loginUser != null) {
                Long userId = loginUser.getId();
                if(!ERoleType.Agent.index().equals(loginUser.getRoleType())){
                    if(ERoleType.Partner.index().equals(loginUser.getRoleType())) {
                        userId = loginUser.getParentId();
                        AgentRelationBusinessConfig agentRelationBusiConfig = AgentRelationBusinessConfigService.self()
                        		.getByKeys(loginUser.getParentId(), loginUser.getId(),EBusinessType.BXSCN_SHOP.index());
                        if(agentRelationBusiConfig == null || AgentRelationBusinessConfigEnum.EditFeeState.Close.index()
                        		.equals(agentRelationBusiConfig.getEditFeeState())) {
                        	 apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限保存电池类型价格");
                             return apiResp;
                        }
                    }else{
                        apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限保存电池类型价格");
                        return apiResp;
                    }
                }
                
                BXSCNShopFeeTemplate feeTemplate = BXSCNShopFeeTemplateService.self().getById(apiReq.getBody().getTemplateId());
                if(feeTemplate != null) {
                	if(feeTemplate.getUserId().equals(userId)) {
                		List<BXSCNShopFeeTemplateItem> feeTemplateItemList = BXSCNShopFeeTemplateService.self()
                				.findItemByKeys(feeTemplate.getId(),apiReq.getBody().getBatteryTypeId());
                		
                		List<BXSCNShopFeeTemplateItem> addItems = new ArrayList<>();
                 		List<BXSCNShopFeeTemplateItem> updateItems = new ArrayList<>();
                 		List<BXSCNShopFeeTemplateItem> delItems = new ArrayList<>();
                		
                		for(BXSCNShopFeeTemplateItemSaveRequest.Item item : apiReq.getBody().getItems()) {
                			if(item.getToDel() != null && item.getToDel()) {
                				//删除
                				BXSCNShopFeeTemplateItem feeTemplateItem = new BXSCNShopFeeTemplateItem();
	                			feeTemplateItem.setTemplateId(feeTemplate.getId());
	                			feeTemplateItem.setBatteryTypeId(apiReq.getBody().getBatteryTypeId());
	                			feeTemplateItem.setType(item.getType());
	                			delItems.add(feeTemplateItem);
                			}else {
	                			if(item.getDepositPrice() < 0 || item.getDayPrice() < 0) {
	                				apiResp.setMsg("金额错误，请检查");
	                                return apiResp;
	                			}
	                			
	                			BXSCNShopFeeTemplateItem feeTemplateItem = new BXSCNShopFeeTemplateItem();
	                			feeTemplateItem.setTemplateId(feeTemplate.getId());
	                			feeTemplateItem.setBatteryTypeId(apiReq.getBody().getBatteryTypeId());
	                			feeTemplateItem.setType(item.getType());
	                			feeTemplateItem.setDepositMoney(NumberTools.changeMoney(item.getDepositPrice()));
	                			feeTemplateItem.setDayMoney(NumberTools.changeMoney(item.getDayPrice()));
	                			feeTemplateItem.setCreateDate(new Date());
	                			boolean flag = true;
	                			if(feeTemplateItemList != null && feeTemplateItemList.size() > 0) {
	                				for(BXSCNShopFeeTemplateItem temp : feeTemplateItemList) {
	                					if(temp.getType().equals(item.getType())) {
	                						updateItems.add(feeTemplateItem);
	                						flag = false;
	                						break;
	                					}
	                				}
	                			}
	                			if(flag) {
	                				addItems.add(feeTemplateItem);
	                			}
                			}
                		}
                		
                		if(BXSCNShopFeeTemplateService.self().saveItem(addItems,updateItems,delItems)) {
           				 	apiResp.setCode(ClientAPICodeConstants.SUCCESS,null);
                		}
                	}else {
                		apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限保存电池类型价格");
                        return apiResp;
                	}
                }else {
                	apiResp.setMsg("未找到价格模版");
                    return apiResp;
                }
            }
        }
        return apiResp;
    }

	@Route(value = "/agent/api/v1/bxscn/shop/fee_template/del.do")
    public DefaultAPIResponse doDel(HttpServletRequest request) {
        DefaultAPIResponse apiResp = new DefaultAPIResponse(ClientAPICodeConstants.EXECUTE_ERROR, "删除收费模版失败");
        BXSCNFeeTemplateDelRequest apiReq = WebUtils.getJsonRequest(request, BXSCNFeeTemplateDelRequest.class);
        if (apiReq != null && apiReq.getBody().getId() != null) {
            LoginUser loginUser = WebUtils.getAttribute(request, WebConstants.ATTR_LOGIN_USER, LoginUser.class);
            if(!ERoleType.Agent.index().equals(loginUser.getRoleType())){
                if(ERoleType.Partner.index().equals(loginUser.getRoleType())) {
                    AgentRelationBusinessConfig agentRelationBusiConfig = AgentRelationBusinessConfigService.self()
                    		.getByKeys(loginUser.getParentId(), loginUser.getId(),EBusinessType.BXSCN_SHOP.index());
                    if(agentRelationBusiConfig == null || AgentRelationBusinessConfigEnum.EditFeeState.Close.index()
                    		.equals(agentRelationBusiConfig.getEditFeeState())) {
                    	 apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限删除收费模版");
                         return apiResp;
                    }
                }else{
                    apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限删除收费模版");
                    return apiResp;
                }
            }
            Long total = PlaceBusinessConfigService.self().countByFeeTemplateId(EBusinessType.BXSCN_SHOP.index(),apiReq.getBody().getId());
            if(total != null && total > 0){
                apiResp.setMsg("该收费模版正在使用，不允许删除");
                return apiResp;
            }

            try {
                if(BXSCNShopFeeTemplateService.self().deleteById(apiReq.getBody().getId())){
                    apiResp.setCode(ClientAPICodeConstants.SUCCESS,null);
                }
            } catch (LogicException e) {
                apiResp.setMsg(e.getMessage());
            }
        }
        return apiResp;
    }
	
	@Route(value = "/agent/api/v1/bxscn/shop/fee_template/item/del.do")
    public DefaultAPIResponse doItemDel(HttpServletRequest request) {
        DefaultAPIResponse apiResp = new DefaultAPIResponse(ClientAPICodeConstants.EXECUTE_ERROR, "删除电池类型价格失败");
        BXSCNShopFeeTemplateItemDelRequest apiReq = WebUtils.getJsonRequest(request, BXSCNShopFeeTemplateItemDelRequest.class);
        if (apiReq != null && apiReq.getBody().getTemplateId() != null && StringTools.isNotBlank(apiReq.getBody().getBatteryTypeId())) {
            LoginUser loginUser = WebUtils.getAttribute(request, WebConstants.ATTR_LOGIN_USER, LoginUser.class);
            if(!ERoleType.Agent.index().equals(loginUser.getRoleType())){
                if(ERoleType.Partner.index().equals(loginUser.getRoleType())) {
                    AgentRelationBusinessConfig agentRelationBusiConfig = AgentRelationBusinessConfigService.self()
                    		.getByKeys(loginUser.getParentId(), loginUser.getId(),EBusinessType.BXSCN_SHOP.index());
                    if(agentRelationBusiConfig == null || AgentRelationBusinessConfigEnum.EditFeeState.Close.index()
                    		.equals(agentRelationBusiConfig.getEditFeeState())) {
                    	 apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限删除收费模版");
                         return apiResp;
                    }
                }else{
                    apiResp.setCode(ClientAPICodeConstants.NOT_POWER,"无权限删除收费模版");
                    return apiResp;
                }
            }
            try {
                if(BXSCNShopFeeTemplateService.self().deleteItemByKeys(apiReq.getBody().getTemplateId(),apiReq.getBody().getBatteryTypeId())){
                    apiResp.setCode(ClientAPICodeConstants.SUCCESS,null);
                }
            } catch (LogicException e) {
                apiResp.setMsg(e.getMessage());
            }
        }
        return apiResp;
    }
}
